/**
 * _Authentication class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 * @version 0.7.2
 */

Ext.apply(ext4yii,{
    _Authentication : {

        resetForm:function()
        {
            loginForm.getForm().reset();
            txtUsername.focus(true,500);
        },

        showLoginWindow:function()
        {
            loginWindow.show();
            ext4yii._Authentication.resetForm();
        },
        
        startAuthentication:function()
        {
            if(loginForm.getForm().isValid())
            {
                loginForm.getForm().submit({
                    waitTitle: "Authenticating....",
                    waitMsg:"Please Wait...",
                    success: function(fp, o)
                    {
                        loginWindow.close();
                        Ext.MessageBox.show({
                            msg:"Please Wait...",
                            title:"Redirecting...",
                            wait:true,
                            waitConfig: {interval:200},
                            minWidth:300
                        });
                        window.location.href = o.result.url;
                    },

                    failure: function(fp, o)
                    {
                        Ext.MessageBox.show({
                            title:"Login Failed.",
                            msg:"Invalid username or password. Please try again.",
                            buttons: Ext.Msg.OK,
                            icon:Ext.MessageBox.ERROR,
                            fn:function()
                            {
                                ext4yii._Authentication.resetForm();
                            }
                        });
                    }
                })
            }
        }
    }
});
